<template>
    <div>
        <el-table max-height="510px" :data="bannerList" border style="width: 100%">
            <el-table-column prop="id" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="title" label="轮播图标题" width="180">
            </el-table-column>
            <el-table-column label="图片" width="170">
                <template slot-scope="item">
                    <div>
                        <img class="img" v-if="item.row.img" :src="$img + item.row.img" alt="">
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div>
                        {{ item.row.status == 1 ? '正常' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="mini" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>

<script>
// 辅助性函数
import { mapActions, mapGetters } from 'vuex'
// 引入接口
import { bannerDel } from '../../request/api'
export default {
    data() {
        return {
        }
    },
    computed: {
        ...mapGetters({
            bannerList: 'banner/getBannerList'
        }),
    },
    mounted() {
        // 页面加载抵用轮播图列表接口
        this.bannerListAction()
    },
    methods: {
        ...mapActions({
            bannerListAction: 'banner/bannerListAction'
        }),
        // 编辑按钮
        edit(id) {
            this.$emit('edit', id)
        },
        // 删除事件
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 调用删除接口
                bannerDel({ id })
                    .then(res => {
                        console.log(res, '删除成功');
                        this.$message.success(res.msg)
                        // 重新调用列表
                        this.bannerListAction()
                    })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

        }
    }
};
</script>

<style  lang="less" scoped>
.img {
    width: 150px;
    height: 150px;
}
</style>
